<template>
	<view>
		<u-dropdown :border-bottom="true">
			<u-dropdown-item v-model="classesIndex" @change="change" :title="classesValue" :options="titleList"></u-dropdown-item>
		</u-dropdown>
		<view v-if="classesIndex !== -1">
			<u-table v-if="classesIndex === 0">
				<u-tr>
					<u-th>教保师名称</u-th>
					<u-th>岗位</u-th>
					<u-th>电话号码</u-th>
				</u-tr>
				<u-tr v-for="(item, index) in teachetList" :key="index">
					<u-td class="td">{{item.realName || ''}}</u-td>
					<u-td class="td">{{item.positionName}}</u-td>
					<u-td class="td">
						<view @click="makePhoneCall(item.mobile)" class="phone-view">
							{{item.mobile}}
						</view>
					</u-td>
				</u-tr>
			</u-table>
			<u-table v-else>
				<u-tr>
					<u-th>家长姓名</u-th>
					<u-th>学生姓名</u-th>
					<u-th>电话号码</u-th>
				</u-tr>
				<u-tr v-for="(item, index) in parentList[classesIndex - 1].linkmanData" :key="index">
					<u-td class="td">{{item.userName}}</u-td>
					<u-td class="td">{{item.childrenName}}</u-td>
					<u-td class="td">
						<view @click="makePhoneCall(item.userPhone)" class="phone-view">
							{{item.userPhone}}
						</view>
					</u-td>
				</u-tr>
			</u-table>
		</view>
		<!-- <u-select v-model="show" :list="titleList"></u-select> -->
	</view>
</template>

<script>
	import { getContactTeachers, getContactParents } from '@/api/common.js'
	export default {
		data() {
			return {
				classesIndex: 0,
				classesValue: '园区',
				titleList: [],
				
				teachetList: [],
				parentList: [],
				
				show: false,
			}
		},
		onLoad() {
			this.getTeacher();
		},
		methods: {
			getTeacher() {
				let item = {
					label: '园区',
					value: 0
				}
				this.titleList.push(item)
				getContactTeachers().then(res => {
					console.log(res);
					this.teachetList = res.data;
					this.getParent();
				})
			},
			
			getParent() {
				getContactParents().then(res => {
					console.log(res);
					this.parentList = res.data;
					for (let index in this.parentList) {
						let item = this.parentList[index];
						let itemIndex = parseInt(index) + 1;
						let object = {
							label: item.classData.name,
							value: itemIndex
						}
						this.titleList.push(object)
					}
					// this.show = true;
				})
			},
			
			change(res) {
				console.log(res);
				this.classesValue = this.titleList[res].label
			},
			
			makePhoneCall(phoneNumber) {
				uni.makePhoneCall({
				    phoneNumber: phoneNumber
				});
			}
		}
	}
</script>

<style lang="scss">
	.td {
		height: 70rpx;
		overflow: hidden;
	}
	
	.phone-view{
		text-decoration: underline;
	}
</style>
